﻿Shader "Hidden/PostProcessing/Wave"
{
	HLSLINCLUDE

#include "../StdLib.hlsl"

		// 属性声明
		TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
	half _WaveStrength;


	float4 Frag(VaryingsDefault i) : SV_Target
	{
	   half2 dv = half2(0.5,0.5) - i.texcoord;
	   dv = dv * half2(_ScreenParams.x/_ScreenParams.y,1);


	   half dis = sqrt(dv.x*dv.x + dv.y * dv.y);
	   
	   half _distanceFactor = 10.0/(_WaveStrength + 0.1);
	   half _totalFactor = 20.0;
	   half _waveWith = 0.25;
	   half _curWaveDis = _WaveStrength;
	   
	   half sinFactor = sin(dis * _distanceFactor) * _totalFactor * 0.01;
	   
	   half discardFactor = clamp(_waveWith - abs(_curWaveDis - dis),0,1);
	   
	   half2 dv1 = normalize(dv);
	   
	   half2 offset = dv1 * sinFactor * discardFactor;

		// 采样RenderTexture
		float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + offset);

		// 亮度
		//color.rgb *= _WaveStrength;

		


		return color;
	}

		ENDHLSL

		SubShader
	{
		Cull Off 
        ZWrite Off 
		ZTest Always

			Pass
		{
			HLSLPROGRAM

				#pragma vertex VertDefault
				#pragma fragment Frag

			ENDHLSL
		}
	}

}
